package game;

import java.awt.Point;

/**
 *	@(#)CitySystem.java
 *
 *	The <code>CitySystem</code> class represents the coordinate system of
 *	a player's cities and provides methods to calculate pixel locations
 *	within these cities from given system locations and vice-versa.
 *
 *	@author Grzegorz Kobiela
 *	@version 1.0 2008/5/9
 */
public abstract class CitySystem
{
	/** The length of the unit in x-direction. */
	public static final int UNIT_X = 35;

	/** The length of the unit in y-direction. */
	public static final int UNIT_Y = 35;

	/** The offset to the origin in x-direction. */
	public static final int OFFSET_X = 2;

	/** The offset to the origin in y-direction. */
	public static final int OFFSET_Y = 2;

	/**
	 *	Returns the pixel coordinates of the given system point.
	 *	@param point the point
	 *	@return the pixel coordinates
	 */
	public static Point getPixel(Point point) {
		return getPixel(point.x, point.y);
	}

	/**
	 *	Returns the pixel coordinates of the given system point.
	 *	@param x the x-coordinate
	 *	@param y the y-coordinate
	 *	@return the pixel coordinates
	 */
	public static Point getPixel(double x, double y) {
		return new Point(
			(int)Math.round(OFFSET_X + UNIT_X * x),
			(int)Math.round(OFFSET_Y + UNIT_Y * y)
		);
	}

	/**
	 *	Returns the corresponding point in the coordinate system.
	 *	@param pixel the pixel coordinates
	 *	@return the corresponding system point
	 */
	public static Point getPoint(Point pixel) {
		return getPoint(pixel.x, pixel.y);
	}

	/**
	 *	Returns the corresponding point in the coordinate system.
	 *	@param x the x-coordinate of the given pixel
	 *	@param y the y-coordinate of the given pixel
	 *	@return the corresponding system point
	 */
	public static Point getPoint(double x, double y) {
		return new Point(
			(int)Math.round((x - OFFSET_X) / UNIT_X),
			(int)Math.round((y - OFFSET_Y) / UNIT_Y)
		);
	}
}